Add # typeprof:ignore comment to suppress diagnostics#417
Merged
Conversation
Append `# typeprof:ignore` at the end of a line to suppress any
diagnostic whose code range starts on that line. This is useful for
code patterns that TypeProf cannot analyze precisely.
def check
Foo.new.accept_int("str") # typeprof:ignore
end
The keyword matches Steep's `# steep:ignore` to keep the Ruby type
checker ecosystem consistent.
The structure (collecting comment line ranges and filtering at
ProgramNode#each_diagnostic) is borrowed from #306 which proposed
a similar feature with `# typeprof:disable`/`enable`.
Co-Authored-By: Masato Sugiyama <public@smasato.net>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
For suppressing diagnostics across multiple lines, support a block
form bracketed by `# typeprof:ignore:start` and `# typeprof:ignore:end`
comments:
# typeprof:ignore:start
foo(1, 2)
bar(1, 2)
# typeprof:ignore:end
An unmatched `:start` extends to the end of the file. The keywords
follow Steep's `# steep:ignore:start`/`:end` convention.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a way to suppress TypeProf diagnostics on specific lines via comments, following Steep's
# steep:ignoreconvention.Syntax
Inline form — suppresses diagnostics whose code range starts on the same line:
Block form — suppresses diagnostics between
:startand:end:An unmatched
# typeprof:ignore:startextends to the end of the file.Why
ignore(and notdisable/enable)To match Steep's existing convention so that users of the Ruby type-checker ecosystem only need to remember one keyword:
# steep:ignore# typeprof:ignore# steep:ignore:start# typeprof:ignore:start# steep:ignore:end# typeprof:ignore:endImplementation
AST.collect_ignore_ranges(inlib/typeprof/core/ast.rb) scans Prism comments at parse time and returns a list of ignored line ranges.ProgramNodestores those ranges and filters them out ineach_diagnosticbased on each diagnostic's starting line.The whole feature is ~40 lines plus tests.
Relation to #306
This PR supersedes #306 by @x-smasato, which proposed the same feature with
# typeprof:disable/# typeprof:enablekeywords and a dedicatedDiagnostic::DisableDirective::Scanner/Filtermodule pair.Differences from #306:
typeprof:ignore/:start/:endto align with Steep (see above).ast.rband a few lines inProgramNode#each_diagnostic, since the logic is short enough that splitting it across files felt heavier than the implementation deserved.@x-smasato's authorship is preserved as
Co-Authored-Byon the first commit. Thanks to them for the original proposal and design — the structure (scan at parse time, filter atProgramNode#each_diagnostic) is borrowed from #306.I'll close #306 once this lands.